package com.wms.controller;

import com.mes.entity.User;
import com.wms.service.XtReturnService;
import com.yy.base.page.Message;
import com.yy.base.util.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("XtReturnList")
public class XtReturnController {
    @Autowired
    private XtReturnService xtReturnService;



    //保存退料信息
    @ResponseBody
    @RequestMapping(value="saveXtReturnList",method= RequestMethod.POST)
    public Message saveXbkXjListByCode(HttpServletRequest request){
        Message msg = new Message();
        try{
            String rfid = request.getParameter("code");   //RFID

            String code = rfid.replaceAll(" ", "");

            List<Map<String, Object>> ListProduct = xtReturnService.getBatchnorLists(code); //传过来的是RFID号

            if(ListProduct.size() == 0 ){
                msg.setData("XtListData","false");
                return msg;
            }
            String warehouseID = "1E0A69B1B7BB4EECB232D6989684C4D7";
            String locatorID = null;
            User user = UserUtil.getUser();
            String batchId = ListProduct.get(0).get("BATCHID").toString();  //BATCH_ID
            String DWID = ListProduct.get(0).get("DWID").toString();  //单位ID
            String ITEMID = ListProduct.get(0).get("ITEMID").toString();  //ITEM_ID
            xtReturnService.inStorageInOut(warehouseID,batchId, locatorID, 1, DWID, "", user, code);
            xtReturnService.updateStorageBatchItemStatus(ITEMID);


        }catch (Exception e){
            msg.setData("result","false");
            e.printStackTrace();
        }
        return msg;
    }
}
